package xbuf

import "sync"

type Pool struct {
	sync.Pool

	BufferSize int
}

func (this *Pool) Get() *Buffer {
	v := this.Pool.Get()
	if v == nil {
		if this.BufferSize == 0 {
			this.BufferSize = 512 // 默认缓冲区大小
		}
		return New(this.BufferSize)
	}
	return v.(*Buffer).Clear()
}

func (this *Pool) Put(xb *Buffer) {
	this.Pool.Put(xb)
}

func NewPool(bufsize int) *Pool {
	return &Pool{BufferSize: bufsize}
}
